/*===========================================================================================    * Date: Sept 2018
	* Purpose: Transform maps created in ArcGiS into STATA
	* DATASETS Used:	
		- "$MOLA/LL_POINTS1881_Soc_Civ_Near.shp"	
	* DATASETS Created:
		- "$MOLA/ll_pl_pa_points"
		- "$MOLA/ll_point1881_soc_civ_near"
===========================================================================================*/

gl MOLA "/Users/`c(username)'/Dropbox/NetworkParish2016/Occupational_Choice/Submission/Final_ReStat/Codes/MOLA"

// 1. Street points + Ecclesiastical parish + Board of Works/Vestry + Neighbouring parish info

shp2dta using "$MOLA/LL_PL_PA_POINTS_1881.shp", database(ll_pl_pa_points) coordinates(londoncoord2) genid(id) replace

use "$MOLA/ll_pl_pa_points", clear

drop OBJECTID_1 OBJECTID_2 OBJECTID_3 Map1871 id
rename OBJECTID objectid 
rename ROCQUE_ID rocque_id 
rename P_NAME p_name 
rename NAME name 
rename ORIG_FID orig_fid

save "$MOLA/ll_pl_pa_points", replace

// 2. Street points + Ecclesiastical parish + Board of Works/Vestry + Neighbouring parish info

shp2dta using "$MOLA/LL_POINTS1881_Soc_Civ_Near.shp", database(ll_point1881_soc_civ_near) coordinates(londoncoord2) genid(id) replace

use "$MOLA/ll_point1881_soc_civ_near.dta", clear

label data "Map_data"
label variable id "unique ID"
rename IDMOLA civil
label variable civil "Civil parish identifier"
rename IDSocial social
label variable social "Social parish identifier"
label variable P_NAME  "address"
label variable NAME "census parish"
rename POINT_X longitude 
label variable longitude "Longitude"
rename POINT_Y latitude 
label variable latitude "Latitude"
rename NEAR_FID ID_socialborder
label var ID_socialborder "Unique ID of closest social border (Not IDSocial)"
rename NEAR_DIST dist_socialborder
label var dist_socialborder "Distance to closest social border"
rename Distance dist_civilborder
label var dist_civilborder "Distance to closest civil border"

order ID_socialborder dist_socialborder, after(dist_civilborder)
label var IDSocial_L "IDSocial on the Left"
label var IDSocial_R "IDSocial on the Right"
drop ORIG_FID FID_1_1 FID_1 OBJECTID SHAPE_Leng Shape_Area Shape_Le_1 Shape_Ar_1 FID_12 LEFT_FID RIGHT_FID

save "$MOLA/ll_point1881_soc_civ_near", replace

